package com.xjtu.controller.user;

import com.xjtu.dto.UserLoginDTO;
import com.xjtu.entity.Elderly;
import com.xjtu.mapper.UserMapper;
import com.xjtu.result.Result;
import com.xjtu.service.ElderlyService;
import com.xjtu.service.UserService;
import com.xjtu.vo.ElderlyVo;
import com.xjtu.vo.UserLoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/user")
@Slf4j
@Api(tags = "用户端用户接口")
public class UserController {

    @Autowired
    private ElderlyService elderlyService;

    @Autowired
    private UserService userService;
    @PostMapping("/login")
    @ApiOperation("小程序端登陆")
    private Result<UserLoginVo> login(@RequestBody UserLoginDTO userLoginDTO){
        log.info("当前登陆的用户为{}",userLoginDTO);
        UserLoginVo userLoginVo = userService.login(userLoginDTO);
        return Result.success(userLoginVo);
    }

    @PostMapping("/logout")
    @ApiOperation("退出登陆")
    private Result logout(){
        return Result.success();
    }

    @GetMapping("/elders")
    @ApiOperation("获取老人信息")
    private Result<List<Elderly>> getEldery(){
        List<Elderly> resp = elderlyService.getAll();
        return Result.success(resp);
    }
}
